import java.util.Arrays;

/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.05.00
 *Time:00:00
 */
public class Main{
    //双指针遍历
    public void merge2(int[] nums1, int m, int[] nums2, int n) {
        //双指针查找
        int p1 = m - 1;
        int p2 = n - 1;
        int pos = m + n - 1;
        //存放数组元素
        int cur;
        //排序到最后一个元素
        while(p1 >= 0 || p2 >= 0){
            if(p1 == -1){
                cur = nums2[p2--];
            }else if(p2 == -1){
                cur = nums1[p1--];
            }else if(nums1[p1] > nums2[p2]){
                cur = nums1[p1--];
            }else{
                cur = nums2[p2--];
            }
            //赋值
            nums1[pos--] = cur;
        }
    }
     public void merge1(int[] nums1, int m, int[] nums2, int n) {
          //双指针查找
          int p1 = 0;
          int p2 = 0;
          //创建排序数组
          int[] sorted = new int[m + n];
          //存放数组元素
          int cur;
          //排序到最后一个元素
          while(p1 < m || p2 < n){
             if(p1 == m){
               cur = nums2[p2++];
             }else if(p2 == n){
                cur = nums1[p1++];
             }else if(nums1[p1] < nums2[p2]){
                cur = nums1[p1++];
             }else{
                cur = nums2[p2++];
             }
             //赋值
             sorted[p1 + p2 - 1] = cur;
          }
          //2.将sorted数组赋值给nums1
          for(int i = 0;i < m + n;i++){
            nums1[i] = sorted[i];
          }
        }
    public int removeDuplicates1(int[] nums) {
        int len = nums.length;
        int i = 0;
        for(;i < len - 1;i++) {
            if (nums[i] == nums[i + 1]) {
                for (int j = i; j < len - 1; j++) {
                    nums[j] = nums[j + 1];
                }
                i--;
                len--;
            }
        }
        return len;
    }
    public static int removeElement(int[] nums, int val) {
        int cnt = 0;
        int len = nums.length;
        for(int i = 0;i < len;i++){
            if(nums[i] == val){
                for(int j = i;j < nums.length - 1;j++){
                    nums[j] = nums[j+1];
                }
                i--;
                len--;
            }
            else cnt++;
        }
        return cnt;
    }
    public static void main1(String[] args) {
        int[] nums = {3,2,2,3};
        removeElement(nums,3);
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        };
    }
}